
//
//  HWWebviewController.m
//  JWC
//
//  Created by lanou on 16/4/6.
//  Copyright © 2016年 陈帅. All rights reserved.
//

#import "HWWebviewController.h"

@interface HWWebviewController ()

@property (nonatomic, strong)UIWebView *webView;

@property (nonatomic, strong)UIButton *leftBtn;

@end

@implementation HWWebviewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.webView];
    
    [self setNavBar];
}

- (void)setNavBar
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.leftBtn];
}

- (UIButton *)leftBtn
{
    if (_leftBtn == nil)
    {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_leftBtn setBackgroundImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [_leftBtn setBackgroundImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        [_leftBtn addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        [_leftBtn setTitle:@"返回" forState:UIControlStateNormal];
//        [_leftBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
//        _leftBtn.titleLabel.textAlignment = NSTextAlignmentRight;
        _leftBtn.size = _leftBtn.currentBackgroundImage.size;
    }
    return _leftBtn;
}

- (void)backButtonAction:(UIButton *)button
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (UIWebView *)webView
{
    if (_webView == nil)
    {
        _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    }
    return _webView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
